import { BaseWindow } from "../../../../component/window/BaseWindow";
import { GameConst } from "../../../../component/gconst/GameConst";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { ENpcEffect } from "../../../../../Message/Public/ENpcEffect";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { SecTimerView } from "../../common/SecTimerView";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { EventName } from "../../../mvc/EventName";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LongProgressBar } from "../../player/LongProgressBar";
import { ImagesConst } from "../../../resource/ImagesConst";
import { NpcEffectRule } from "../../../rules/NpcEffectRule";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { MsgManager } from "../../../manager/MsgManager";
import { EffectManager } from "../../../manager/EffectManager";
import { EGuildStructureType } from "../../../../../Message/Public/EGuildStructureType";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GScrollPane } from "../../../../../com/mui/controls/GScrollPane";
import { TaskTargetInfo } from "../../../model/TaskTargetInfo";
type int = number;
//class GuildAuraWindow
    
    export  class GuildAuraWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._maxAura = GameConst.GuildReikiRange;
            this.setSize(560, 395);
            this.titleHeight = 28;
            title = Language.getString(57444);
            this.init();
            return;
        }

        public init(): void
        {
            this._npcInfo = Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcGuildMoneyTree);
            this.addChild(new GImageBitmap("GuildAuraTree.png", 19, 40));
            ObjCreate.createTextField(Language.getString(57445), 60, 260, 220, 40, this, new GTextFormat(FontUtil.songtiName, 16, 11661311));
            this._levelTxt = ObjCreate.createTextField("0", 35, 255, 220, 40, this, new GTextFormat(FontUtil.songtiName, 22, 15788607, true));
            this._tipTxt = ObjCreate.createTextField(Language.getString(57446), 110, 305, 295, 40, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._timeTxtView = new SecTimerView();
            this._timeTxtView.mouseEnabled = false;
            var loc1=new GTextFormat(FontUtil.songtiName, 14, 15788607, true);
            loc1.align = flash.text.TextFormatAlign.LEFT;
            this._timeTxtView.defaultTextFormat = loc1;
            this._timeTxtView.filters = [FilterConst.glowFilter];
            this._timeTxtView.setParse(Language.getString(57458));
            this._timeTxtView.addEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            ObjCreate.setObjAttri(this._timeTxtView, 210, 303, 150, 25, this);
            ObjCreate.createTextField(Language.getString(57447), 27, 330, 220, 40, this, GlobalStyle.textFormat6);
            this._auraBar = new LongProgressBar();
            this._auraBar.progressBarClass = ImagesConst.Mofatiao;
            this._auraBar.setBgSize(200, 14);
            this._auraBar.move(90, 330);
            this._auraBar.setValue(0, this._maxAura);
            this.addChild(this._auraBar);
            this._addBtn = ObjCreate.createGButton(Language.getString(57449), 130, 355, 70, 28, this, "ButtonSpecial");
            this._addBtn.toolTipData = Language.getString(57480);
            this._addBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAddBtnClickHandler);
            ObjCreate.createBg(318, 39, 225, 342, this);
            ObjCreate.createTextField(Language.getString(57450), 320, 45, 220, 40, this, new GTextFormat(FontUtil.songtiName, 14, 15788607, true));
            this._descText = ObjCreate.createTextField("", 320, 65, 215, 315, this, GlobalStyle.textFormat1);
            this._descText.mouseWheelEnabled = false;
            this._descText.wordWrap = true;
            this._descText.multiline = true;
            this._descText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descText.htmlText = Language.getString(57451);
            return;
        }

        public updateLevel(arg1: int): void
        {
            this._level = arg1;
            this._levelTxt.text = arg1.toString();
            this._tipTxt.visible = arg1 > 0;
            return;
        }

        public updateAura(arg1: int): void
        {
            this._auraBar.setValue(arg1, this._maxAura);
            return;
        }

        public updateLeftTime(arg1: int): void
        {
            this._timeTxtView.setLeftTime(arg1);
            return;
        }

        public shakeSuccess(): void
        {
            this._addBtn.enabled = false;
            this.hide();
            return;
        }

        /* internal  */onAddBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=false;
            var loc2=null;
            if (this._isRiped) 
            {
                loc1 = NpcEffectRule.checkDistanceByCode(this._npcInfo.id);
                if (loc1) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildTreeShake));
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(57508));
                }
            }
            else 
            {
                loc2 = Cache.instance.guild.myGuildInfo;
                if (loc2) 
                {
                    if (loc2.contribution > 10) 
                    {
                        if (this._level == 0) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(57461));
                            return;
                        }
                        if (this._timeTxtView.getLeftTime() <= 0) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(57462));
                            return;
                        }
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildTreeAddAura, 10));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(57459));
                    }
                }
            }
            return;
        }

        /* internal  */onSecViewTimeChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            this._isRiped = loc1 == 0;
            var loc2=Cache.instance.guild.isShaked;
            if (this._isRiped) 
            {
                this._tipTxt.visible = false;
                this._timeTxtView.text = Language.getString(57497);
                this._addBtn.label = Language.getString(57506);
                this._addBtn.toolTipData = Language.getString(57507);
                if (loc2) 
                {
                    EffectManager.glowFilterUnReg(this._addBtn);
                }
                else 
                {
                    EffectManager.glowFilterReg(this._addBtn, [new Object /* flash.filters.GlowFilter */(268435302, 1, 6, 6, 4)]);
                }
            }
            else 
            {
                this._tipTxt.visible = true;
                this._addBtn.label = Language.getString(57449);
                this._addBtn.toolTipData = Language.getString(57480);
                EffectManager.glowFilterUnReg(this._addBtn);
                Cache.instance.guild.isShaked = false;
            }
            this._addBtn.enabled = !loc2;
            return;
        }

        /* internal  */showInit(): void
        {
            this.updateLevel(Cache.instance.guild.getStructureLevel(EGuildStructureType.convert(EGuildStructureType._EGuildTree)));
            this.updateAura(Cache.instance.guild.guildTreeAura);
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildTreeGetLeftTime));
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.showInit();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._timeTxtView.stop();
            return;
        }

        /* internal */ /* var */_treeBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_timeTxtView: SecTimerView;

        /* internal */ /* var */_auraBar: LongProgressBar;

        /* internal */ /* var */_timesTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_addBtn: GButton;

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_descText: Object /* flash.text.TextField */;

        /* internal */ /* var */_maxAura: int;

        /* internal */ /* var */_level: int;

        /* internal */ /* var */_isRiped: Boolean;

        /* internal */ /* var */_npcInfo: TaskTargetInfo;
    }
